<?php
namespace Admin\Controller;
use Common\Controller\AdminController;

class YqkController extends AdminController{
	private $_unitList = array('台','套','');

	protected function _initialize()
	{
		parent::_initialize();
		$this->assign('unitList', $this->_unitList);
	}
	public function index(){
		$where = '1=1';
		$where .= $_GET['name'] ? ' and name like "%' . $_GET['name'] . '%"' : '';
	    $list = $this->getList('*', 'yqk', $where, 'id desc', true);
		$this->assign('list', $list);
		$this->display();
	}

	public function add(){
		if(IS_POST){
			$result = $this->updateData($_POST, 'yqk');
			$this->returnResult($result);
		}else{
			$list_cke = $this->getList('id,name', 'cangku', null, 'id asc', true);
			$this->assign('list_cke', $list_cke);
			$this->display();
		}
	}
	public function sy(){
		if(IS_POST){
			//状态 = 2，借出，更新设备借出时间、状态（1:未借出；2:借出）
			$_save = array("jctime" => time(),"status"=>2,"id"=>I('get.id'));
		    $result = $this->updateData($_save, 'yqk',2);
		    if($result){
		    	//产生借出记录，状态 = 2，正在使用（1:使用结束；2:正在使用）
				$_POST['jctime'] = time();
				$_POST['status'] =	2;
				$_POST['cid'] =	I('get.id');
				unset($_POST['id']);
				$result = $this->updateData($_POST, 'yqgl');
		    }
			$this->returnResult($result);
		}else{
             $info = $this->getInfo('*', 'yqk', 'id=' . I('get.id', 0, 'intval'));
		     $this->assign('info', $info);
		     $list_base = $this->getList('id,name', 'js_base', 'type="sysxx"', 'id asc');
			 $this->assign('list_base', $list_base);
		     $this->display();
		}
	}
	public function gh(){
		 	$info = $this->getInfo('*', 'yqk', 'id=' . I('get.id', 0, 'intval'));
			//状态 = 1，未借出；更新设备归还时间、状态（1:未借出；2:借出）
		    $_save = array("ghtime"=> time(),"status"=>1);
		    $result = $this->updateData($_save, 'yqk',2,'id=' . I('get.id', 0, 'intval'));
		    if($result){
		    	//更新归还信息，状态 = 1，使用结束（1:使用结束；2:正在使用）
		    	$_gh=array("ghtime"=> time(),"status"=>1);
		    	$result = $this->updateData($_gh, 'yqgl',2,'cid=' . $info['id']);
		    }
			$this->returnResult($result);
		}
}